<template>
  <div class="login">
    <div class="login-form">
      <h1>登录</h1>
      <input type="text" placeholder="请输入用户名" v-model="username" />
      <input type="password" placeholder="请输入密码" v-model="password" />
      <button @click="login">登录</button>
      <router-link to="/register">注册</router-link>
    </div>
  </div>
</template>

<style scoped>
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  width: 100vw;
}

.login-form {
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  width: 500px;
  height: 400px;
  background-color: #f0f0f0;
  border-radius: 10px;
  box-shadow: 10px 10px 10px 0 rgba(0, 0, 0, 0.1);
}

.login-form input {
  width: 300px;
  height: 30px;
  border-radius: 10px;
  border: 2px solid #ccc;
}

.login-form button {
  width: 150px;
  height: 30px;
  border-radius: 10px;
  border: none;
  background-color: #007bff;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
}
</style>

<script>
import axios from 'axios';
export default {
  name: "Login",
  data() {
    return {
      username: "",
      password: "",
    }
  },
  methods: {
    login() {
      console.log(this.username, this.password);
      axios.post(`http://localhost:3080/user/login`, {
        username: this.username,
        password: this.password,
      }).then(res => {
        if(res.data === "登录成功"){
          alert("登录成功");
          this.$router.push('/task');
        }else{
          alert(res.data);
        }
      });
    },
  },
};
</script>
